<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.数组解构赋值允许我们按照一一对应的关系从数组中提取值然后将值赋给变量
        let ary = [1, 2, 3];
        let [a, b, c, d, e] = ary;
        console.log(a);
        console.log(b);
        console.log(c);
        console.log(d);  //超出的undefined
        console.log(e); //超出的undefined
        console.log('------------------------');

        //2.对象解构允许我们使用变量的名字匹配对象的属性，匹配成功，匹配成功将对象属性赋给变量
        let person = { name: 'zhuhaoran', age: 30, sex: '男' };
        let { name, age, sex } = person;
        console.log(name);
        console.log(age);
        console.log(sex);
        console.log('------------------------');

        //3.2的第二种方法
        let { name: myName, age: myAge } = person;
        console.log(myName);
        console.log(myAge);
    </script>
</body>

</html>